import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../widget/my_text_field.dart';
import '../../widget/my_button.dart';
import 'package:city_pickers/city_pickers.dart';
import '../../services/user.dart';
import '../../services/sign.dart';
import 'package:dio/dio.dart';
import '../../services/event_bus.dart';

class AddressAddPage extends StatefulWidget {
  AddressAddPage({Key key}) : super(key: key);

  _AddressAddPageState createState() => _AddressAddPageState();
}

class _AddressAddPageState extends State<AddressAddPage> {
  String area = '';
  String name = '';
  String phone = '';
  String address = '';
  //监听页面销毁的事件
  dispose() {
    super.dispose();
    eventBus.fire(new AddressEvent('增加成功...'));
    eventBus.fire(new CheckOutEvent('改收货地址成功...'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: true,
        appBar: AppBar(
          title: Text("增加地址",
            style: TextStyle(
                fontSize: 30.sp,
                fontWeight: FontWeight.bold),),
          centerTitle: true,
        ),
        body: Container(
          color: Colors.white,
          padding: EdgeInsets.all(10),
          child: Column(
            children: <Widget>[
              Container(
                width: 700.w,
                height: 100.w,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      width: 700.w,
                      height: 60.w,
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            height: 60.w,
                            width: 180.w,
                            child: Text('姓名'),
                          ),
                          Container(
                            height: 60.w,
                            width: 450.w,
                            child: TextField(
                              decoration: InputDecoration(
                                hintText: '请输入姓名',
                                hintStyle: TextStyle(
                                  fontSize: 30.sp
                                ),
                                border: InputBorder.none,
                              ),
                              onChanged: (value) {
                                this.name = value;
                              },
                            ),
                          ),
                        ],
                      ),
                    ),
                    Divider(),
                    
                  ],
                ),
              ),
              Container(
                height: 100.w,
                width: 700.w,
                child: Column(
                  children: [
                    Container(
                      width: 700.w,
                      height: 60.w,
                      child: Row(
                        children: [
                          Container(
                            height: 60.w,
                            width: 180.w,
                            child: Text('联系电话'),
                          ),
                          Container(
                            height: 60.w,
                            width: 450.w,
                            child: TextField(
                              keyboardType: TextInputType.phone,
                              decoration: InputDecoration(
                                hintText: '请输入联系电话',
                                hintStyle: TextStyle(
                                    fontSize: 30.sp
                                ),
                                border: InputBorder.none,
                              ),
                              onChanged: (value) {
                                this.name = value;
                              },
                            ),
                          ),
                        ],
                      ),
                    ),
                    Divider(),
                  ],
                ),
              ),
              Container(
                height: 100.w,
                width: 700.w,
                child: Column(
                  children: [
                    Container(
                      width: 700.w,
                      height: 60.w,
                      child: Row(
                        children: [
                          Container(
                            height: 60.w,
                            width: 180.w,
                            child: Text('所在地区'),
                          ),
                          Container(
                            height: 60.w,
                            width: 450.w,
                            child: InkWell(
                              child: Row(
                                children: <Widget>[
                                  this.area.length > 0
                                      ? Text('${this.area}',
                                      style: TextStyle(color: Colors.black54))
                                      : Text('省/市/区',
                                      style: TextStyle(color: Colors.black54))
                                ],
                              ),
                              onTap: () async {
                                Result result = await CityPickers.showCityPicker(
                                  context: context,
                                  cancelWidget: Text("取消",
                                      style: TextStyle(color: Colors.blue)),
                                  confirmWidget: Text("确定",
                                      style: TextStyle(color: Colors.blue)),
                                );
                                setState(() {
                                  this.area =
                                  "${result.provinceName}/${result.cityName}/${result.areaName}";
                                });
                              },
                            ),
                          )
                        ],
                      ),
                    ),
                    Divider(),
                    SizedBox(height: 2),
                  ],
                ),
              ),
              Container(
                height: 100.w,
                width: 700.w,
                child: Column(
                  children: [
                    Container(
                      width: 700.w,
                      height: 60.w,
                      child: Row(
                        children: [
                          Container(
                            height: 60.w,
                            width: 180.w,
                            child: Text(
                              '详细地址',
                              style: TextStyle(color: Colors.black),
                            ),
                          ),
                          Container(
                            height: 60.w,
                            width: 450.w,
                            child: TextField(
                              decoration: InputDecoration(
                                hintText: '请输入具体地址',
                                border: InputBorder.none,
                                hintStyle: TextStyle(
                                    fontSize: 30.sp
                                ),
                              ),
                              onChanged: (value) {
                                this.name = value;
                              },
                            ),
                          )
                        ],
                      ),
                    ),
                    Divider(),
                    
                  ],
                ),
              ),
              Container(
                width:700.w,
                height:150.w,
                alignment: Alignment.center,
                child: Column(
                  children: [
                    Row(
                      children: [
                        Checkbox(
                          activeColor:Colors.red,
                          checkColor:Colors.white,
                          value: true,
                          onChanged: (value){
                            value!=value;
                          },
                        ),Text('设为默认地址'),
                      ],
                    ),
                    Divider(),
                  ],
                ),
              ),
              Container(
                margin:EdgeInsets.only(top:50.w),
                child: Container(
                  width: 700.w,
                  height: 80.w,
                  child: FlatButton(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(Radius.circular(30))),
                    child: Text(
                      '立即保存',
                      style: TextStyle(color: Colors.white, fontSize: 35.sp),
                    ),
                    color: Colors.red,
                    onPressed: () async {
                      Navigator.of(context).pop();
                    },
                  ),
                ),
              )
            ],
          ),
        ));
  }
}
